
// import store from '@/store'
import { hasPermission } from '@/utils/permission'

export default {
  inserted(el, binding, vnode) {
    const { value } = binding
    // const permCodes = store.getters && store.getters.permCodes || []
    // const userType = store.getters && store.getters.userType

    // if (userType === -1) {
    //   return
    // }
    if (value && typeof value === 'string') {
      // const permissionCode = value
      // const hasPermission = permCodes.indexOf(permissionCode) >= 0
      if (!hasPermission(value)) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      throw new Error(`need permissionCode! Like v-permission="'admin'"`)
    }
  }
}
